package com.charmzenus.it.common.utils;

/**
 * 异常工具类
 */
public class ExceptionUtil {

    public static String getExceptionAllinformation(Exception ex) {
        String sOut = "";

        String message = ex.getMessage();

        sOut += "message : " + message + "\r\n";
        StackTraceElement[] trace = ex.getStackTrace();

        for (StackTraceElement s : trace) {
            sOut += "\tat " + s + "\r\n";
        }
        return sOut;

    }

    public static  String errorMessage(Exception e) {
        StackTraceElement stackTraceElement= e.getStackTrace()[0];// 得到异常棧的首个元素


        String className = stackTraceElement.getClassName();
        String methodName = stackTraceElement.getMethodName();
        String fileName = stackTraceElement.getFileName();
        int lineNumber = stackTraceElement.getLineNumber();
        String message = e.getMessage();

        String errorMessage = "className => " + className;
        errorMessage += "  ||  message => " + message;
        errorMessage += "  ||  methodName => " + methodName;
        errorMessage += "  ||  fileName => " + fileName;
        errorMessage += "  ||  lineNumber => " + lineNumber;
        return errorMessage;


    }
}
